package game.snake.direction;
import game.Field;
import game.Point;
import game.snake.Snake;
import game.snake.SnakeBody;

/**
 * The up direction of the snake.
 * 
 * @author Sarun Wongtanakarn 5510546166
 * @author Apiwat Jierakulpanit 5510546212
 * @Version 2013.05.01
 */

public class DirectionUp extends Direction{
	
	public DirectionUp(Snake snake) {
		super(snake);
	}

	@Override
	public void changeDirection(Direction direction) {
		if(!(direction instanceof DirectionDown))
			snake.setDirection(direction);
		snake.getHead().setDirection(direction);
	}

	@Override
	public void move(SnakeBody blockBody, Field field) {
		int newY = blockBody.getPoint().Y + 1;
		if(newY > field.getHeight()-1)
			newY = 0 ;
		blockBody.setPoint(field.POINT[blockBody.getPoint().X][newY]);
		
	}

	@Override
	public void growth(Point[][] point) {
		snake.getBody().add(new SnakeBody( point[snake.getTail().getPoint().X][snake.getTail().getPoint().Y - 1] , snake.getTail().getDirection() ));
		
	}
	
}
